package cn.yunbamboos.rest.service.transaction;

import cn.yunbamboos.rest.service.IRestService;

/**
 * 服务事务管理基本实现
 */
public abstract class BaseServiceTransactionManager implements ServiceTransactionManager {

    /**
     * 是否开启事务管理
     */
    private final boolean enable = true;

    @Override
    public final void begin(IRestService service) {
        if (enable) {
            beginService(service);
        }
    }

    @Override
    public final void commit(IRestService service) {
        if (enable) {
            commitService(service);
        }
    }

    @Override
    public final void rollback(IRestService service) {
        if (enable) {
            rollbackService(service);
        }
    }

    @Override
    public final void release(IRestService service) {
        if (enable) {
            releaseService(service);
        }
    }

    public abstract void beginService(IRestService service);

    public abstract void commitService(IRestService service);

    public abstract void rollbackService(IRestService service);

    public abstract void releaseService(IRestService service);
}
